from models_user.models import *

# Create your models here.


# 资产表，就将所有资产名称放入这个表
class Goods(models.Model):
    
    name = models.CharField(max_length=100)


# 楼号表，放入所有楼号
class Tower(models.Model):

    name = models.CharField(max_length=100)


# 楼层
class Floor(models.Model):

    name = models.CharField(max_length=100)


# 房间表，包含所有房间名9#301

# on_delete可跟的关系：
    # CASCADE：联系删除关系，
    # PROTECT：禁止删除关系
    # SET_NULL：主键删除后，从键设置为空，
    # SET_DEFAULT：主键删除后，设置默认值，
    # SET（）：传入一个函数
    # DO_NOTHING：什么都不做，主要看数据库，一般会报错
class Rooms(models.Model):

    room = models.CharField(max_length=100)
    tower = models.ForeignKey(Tower, on_delete=models.PROTECT)
    floor = models.ForeignKey(Floor, on_delete=models.PROTECT)


# 资产明细
class StockControl(models.Model):

    goods = models.ForeignKey(Goods, on_delete=models.PROTECT)
    room = models.ForeignKey(Rooms, on_delete=models.PROTECT)
    user = models.ForeignKey(User, on_delete=models.PROTECT)    # 保管员
    number = models.IntegerField()  # 数量
    unit = models.CharField(max_length=10)  # 单位


class RunningWater(models.Model):
    # 领取人，保管人
    user = models.ForeignKey(User,
                             on_delete=models.PROTECT)
    # 操作人员，录入人员
    ctrl_user = models.ForeignKey(User,
                                  on_delete=models.PROTECT,
                                  related_name='ctrl_user',
                                  )

    goods = models.ForeignKey(Goods, on_delete=models.PROTECT)

    pub_date = models.DateTimeField(auto_now=True)
    # 流水明细
    # 例：u从x房间领取了n个y，到，m房间
    detail = models.CharField(max_length=200)

